package com.lzy.cloud.base.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lzy.cloud.base.dto.ProtocolDto;
import com.lzy.cloud.base.dto.ShopBankDto;
import com.lzy.cloud.base.entity.Protocol;
import com.lzy.cloud.base.mapper.ProtocolMapperExt;
import com.lzy.cloud.base.response.ProtocolResponse;
import com.lzy.cloud.base.service.ProtocolService;
import com.lzy.framework.core.orm.db.Pager;
import com.lzy.framework.core.utils.DozerUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 协议
 *
 * @author lc
 * @version 2018/8/17
 */
@Service
public class ProtocolServiceImpl implements ProtocolService {

    @Autowired
    private ProtocolMapperExt protocolMapperExt;

    @Override
    public Long create(ProtocolDto dto) {
        Protocol protocol = DozerUtils.map(dto, Protocol.class);
        return protocolMapperExt.insertSelective(protocol)>0?protocol.getId():0;
    }

    @Override
    public PageInfo<ProtocolDto> selectList(Pager pager, ProtocolDto map) {
        if (pager != null)
            PageHelper.startPage(pager.getPageNum(), pager.getPageSize());
        List<ProtocolDto> protocolDtos = protocolMapperExt.selectList(map);
        return new PageInfo<>(protocolDtos);
    }

    @Override
    public Boolean update(ProtocolDto map) {
        return protocolMapperExt.update(DozerUtils.map(map,Protocol.class))>0?true:false;
    }

    @Override
    public ProtocolDto find(Long id) {
        return DozerUtils.map(protocolMapperExt.selectByPrimaryKey(id),ProtocolDto.class);
    }
}
